				
        _pos=_this select 0;
        
        //****************************************************
        //************* SETTINGS FREE TO MODIFY **************
        //****************************************************
        
				//Options, percentage is per buildings detected in the area (100% = 1 spawn per building)
				_SpawnUnit=true; //Spawn unit ?
				_SpawnVehicle=true; //Spawn vehicle ?
				_SpawnSide=civilian; //Side of the group
				_populatepercent=35; //% of unit to spawn, based on the number of buildings in the area
				_vehiclepercent=5; //% of vehicle
				_areasize=100; //Size of the area to populate
				_movingpercent=15; //% of units spawned that will move (following sentry waypoint)
				_interiorspawnchance=75; //Chance in % to spawn inside, if the building as interior position.
				
				//Here to define wich units to randomly spawn
				_vehiclestospawn=[];
				_unitstospawn=[];
				_people=_this select 1;
				call compile format["_vehiclestospawn=%1_Land;",_people];
				call compile format["_unitstospawn=%1_Man;",_people];

        //****************************************************
        //***************** End of settings ******************
				//****************************************************
				
				
				
				//Variables inits !!! DO NOT TOUCH !!!
				private ["_randompos","_validpos"];
				_unitsnum=count _unitstospawn;
				_vehiclesnum=count _vehiclestospawn;
				
				_dir=0;
				_numofunittospawn=0;
				_numofvehicletospawn=0;
				_numbuildingpos=0;
				_building=objnull;
				_unitspawnedinside=0;
				_isinside=false;
        _unitstomove=0;
				
				//Looking for buildings in the area
	      _buildings=nearestObjects  [[_pos select 0, _pos select 1],["House","Ruins","Church","FuelStation"],_areasize];
	      _buildingscount=count _buildings;
	      
	      //No buildings in area will end the script
	      if (_buildingscount<1) exitwith {hint "!!! No buildings in the area !!!";};
	      
	      
	     
        
        //Units populatation
        if (_SpawnUnit) then
        {
          _group = createGroup _SpawnSide;
          _numofunittospawn=round(_buildingscount*(_populatepercent/100));
          _unitstomove=round(_numofunittospawn*(_movingpercent/100));
          
         //Lets have alway an happy mover
         if (_unitstomove<1) then {_unitstomove=1;}; 
      
           
          _wp = _group addWaypoint [_pos, 0];
          _wp setWaypointType "MOVE";
          _wp setWaypointSpeed "LIMITED";
          _wp setWaypointBehaviour "SAFE";
          
          for "_x" from 1 to _numofunittospawn do
          {
            ///Random pos in area
            //Random pos in area based on buildings (more coherant for humans being)
            _building=_buildings select (round(random(_buildingscount-1)));
            _numbuildingpos = _building call buildingPosCount;
            //Spawning inside a building if the building as many position and interior chance
            if ((_numbuildingpos>0) and ((round(random(98+1)))>=(100-_interiorspawnchance))) then
            {
              _validpos=_building buildingPos round(random(_numbuildingpos)); 
              if (count (nearestObjects [_validpos, ["Man"], 1])<1) then
              { 
                _unitspawnedinside=_unitspawnedinside+1;
                _isinside=true;
              }
              else 
              {
                _randompos=getpos _building;
                _validpos=_randompos findEmptyPosition [1,_areasize];
              };
            }
            else //Or outside if the buldings doesnt have interior
            {
              _randompos=getpos _building;
              _validpos=_randompos findEmptyPosition [1,_areasize];
            };
            //Avoid men onroad spawn
            while {isonroad _validpos} do
            {
              _randompos=getpos (_buildings select (round(random(_buildingscount-1))));
              _validpos=_randompos findEmptyPosition [1,_areasize];
            };            
            //_unit =_group createunit [_unitstospawn select (round(random(_unitsnum-1))),_validpos,[],0,"NONE"];
            //_group = createGroup _SpawnSide;
            _unit =_group createUnit [_unitstospawn select (round(random(_unitsnum-1))),_validpos,[],0,"NONE"];
            //Readjust position if inside a building
            if (_isinside) then {_unit setpos _validpos};
            //Readjust position if on roof of a building with no position
            if ((!_isinside) and ((getposatl _unit select 2)>2)) then {_unit setposatl [getposatl _unit select 0,getposatl _unit select 1,0];};
            //Random group direction
            _group setFormDir  (round(random 361));
            
            //Handle the moving and stopped units
            if (_x > _unitstomove) then {_unit disableAI "MOVE";};
            
            //First unit (the moving one if moving there is) is leader 
            if (_x==1) then {_group selectLeader _unit;};
  
            _wp = _group addWaypoint [_validpos, 0];
            _wp setWaypointType "MOVE";
            
            
     				_marker_test = createMarkerLocal ["testmarker",_validpos];
    				_marker_test setMarkerShapeLocal "ELLIPSE";
    				_marker_test setMarkerSizeLocal [2, 2];
    				_marker_test setMarkerDirLocal 0;
    				_marker_test setMarkerColorLocal "ColorredAlpha";
    			  sleep 0.1;
    	
    				deletemarker "testmarker";
    				_numbuildingpos=0;
    				_isinside=false;
    				
          };
          _wp setWaypointType "CYCLE";
          
          
        };
        
        //Vehicles population
        if (_SpawnVehicle) then
        {
           _numofvehicletospawn=round(_buildingscount*(_vehiclepercent/100));
           _roadlist = [_pos select 0, _pos select 1] nearRoads _areasize;
           
          for "_x" from 1 to _numofvehicletospawn do
          {        
            _roadnum = count _roadlist;
            _road = _roadlist select round(random (_roadnum-1));
            _roadlist = _roadlist - [_road];
            _validpos=getpos _road;
            _vehicle= _vehiclestospawn select (round(random(_vehiclesnum-1))) createVehicle _validpos;
            //Random direction on the road
            if (round(random 1)>0) then {_dir=0} else {_dir=180};
            _vehicle setDir (direction _road)+_dir;
            //Put the vehicle on the right of the road
            _Offset = [3.5,0,0];
            _validpos = _vehicle modelToWorld _Offset;
            //Make sure the vehicle is not in a wall on the road side
            _validpos = _validpos findEmptyPosition [0.1,10];
            _vehicle setpos _validpos;
            //Velocity to make sur the vehicle follow the slope
            _vehicle setvelocity [0,0,1];
          
    				_marker_testv = createMarkerLocal ["testmarkerv",_validpos];
    				_marker_testv setMarkerShapeLocal "ELLIPSE";
    				_marker_testv setMarkerSizeLocal [5, 5];
    				_marker_testv setMarkerDirLocal 0;
    				_marker_testv setMarkerColorLocal "ColorredAlpha";
    				sleep 0.1;
    				deletemarker "testmarkerv";
          };
        };
   
	      _code=nil;
	      call compile format["
	      _code={
        if (player==user1) then {hint ""Spawned : %2 unit(s) ( %4 moving and %5 inside buildings) and %3 vehicle(s) for %1 building(s)"";};
        };
        ",_buildingscount,_numofunittospawn,_numofvehicletospawn,_unitstomove,_unitspawnedinside];
        //hint format["Spawned : %2 unit(s) ( %4 moving and %5 inside buildings) and %3 vehicle(s) for %1 building(s)",];
        [_code] execVM "scripts\VTS_Functions\runcodeonallclients.sqf"; 
        sleep 2;
        
        [[_pos select 0,_pos select 1,0],_people,100,2500] execvm "computer\console\fillroads.sqf";
